home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / opbonus.arc / POPDOS.ARC / POPDOS.DOC < prev    next >
Text File  |  1991-03-20  |  19KB  |  367 lines

  1.                      POPDOS -- A Swapping TSR DOS Shell
  2.  
  3.                    Copyright (c) 1990 TurboPower Software
  4.                                   May 1990
  5.  
  6. ------- Overview -----------------------------------------------------------
  7.  
  8. POPDOS is a TSR that can activate a DOS shell while almost any application is
  9. running, hence providing the ability to run DOS commands and even other
  10. applications within programs that didn't originally allow it. POPDOS keeps
  11. only about 6K of normal DOS memory when it goes resident, but can provide up
  12. to about 600K of free DOS space when it pops to DOS. Besides being a useful
  13. utility in its own right, POPDOS demonstrates how to incorporate the same
  14. capability in other TSRs written using Object Professional, TurboPower's
  15. class library for Turbo Pascal 5.5.
  16.  
  17. POPDOS uses two forms of swapping technology to maximize the amount of memory
  18. available to the DOS shell. First, POPDOS is a swappable TSR: when its hot key
  19. is pressed, POPDOS swaps out the applications loaded after it and swaps itself
  20. in. Most of the memory area that it reclaims in this way isn't used directly
  21. by POPDOS. Besides the code, data, and stack space that POPDOS actually uses,
  22. it retains a variable amount of heap space that provides the free RAM for the
  23. DOS shell itself. Second, POPDOS uses a swapping DOS shell: after the
  24. swappable TSR takes control, it swaps the TSR's code and data back out,
  25. shrinks its memory allocation to the minimum, and calls the DOS EXEC function
  26. to activate a DOS command line. The amount of memory free at this command line
  27. can range from 30K to over 600K depending on when and how POPDOS was loaded.
  28. After you type "Exit" at the command line, the sequence is reversed and the
  29. original application regains control.
  30.  
  31. For reasons that aren't clear at this time, POPDOS does not work with PC-DOS
  32. 2.0 or 2.1. Either piece of swapping technology -- swappable TSR's or swapping
  33. exec -- works fine by itself, but the two don't combine. Interestingly, AT&T
  34. DOS version 2.11 works with POPDOS, which suggests the presence of a bug in
  35. the earlier DOS versions. POPDOS.EXE as supplied will not load for any DOS
  36. version prior to 3.00.
  37.  
  38. POPDOS requires Object Professional version 1.02 or later to compile. Download
  39. POPDSE.LZH from LIB 6 of the PCVENB forum on CompuServe if you'd like just the
  40. precompiled EXE file.
  41.  
  42.  
  43. ------- Installing POPDOS --------------------------------------------------
  44.  
  45. POPDOS will use either EMS (expanded memory), XMS (extended memory), or disk
  46. space for its swapping medium. When using EMS, it consumes about X+45
  47. kilobytes of EMS space (rounded up to the nearest 16K boundary), where X is
  48. the amount of RAM to be free when the DOS shell starts. When using XMS or
  49. disk, it uses about n*(X+15)+30 kilobytes of space, where n is either 1 or 2
  50. depending on whether single or double file swapping is used. The single file
  51. swapping option is described in more detail below.
  52.  
  53. You can install POPDOS simply by typing its name at the DOS command line. It
  54. provides the following default behavior:
  55.  
  56.   - all RAM that is free at the time POPDOS is loaded, less about 20K, will
  57.     be available to the DOS shell
  58.   - EMS, if available, will be used for swap space
  59.   - dual swap files located in the root directory of drive C: will be used
  60.     if EMS is not available
  61.   - swap files will be marked hidden
  62.   - hot key will be <Alt><F10>
  63.   - the mouse state will be saved and restored if the mouse driver allows
  64.  
  65. All of these defaults may be modified by using the command line options
  66. described below.
  67.  
  68. Unload POPDOS from memory by typing POPDOS /U from the DOS command line. The
  69. unload will succeed only if no TSRs that grab interrupt vectors have been
  70. loaded after POPDOS. POPDOS will also refuse to unload if you try to do so
  71. from within its own DOS shell.
  72.  
  73. The following table summarizes the POPDOS command line options:
  74.  
  75.   /1         single swap file
  76.   /A         visible attribute for swap files
  77.   /D         force disk swapping even if EMS available
  78.   /F kbytes  specify approx. kbytes free within DOS shell
  79.   /H hexkey  specify TSR hot key in hex
  80.   /K         kill mouse management code
  81.   /M         disable swap message
  82.   /S path    specify drive and directory for swap files
  83.   /U         unload TSR
  84.   /X         use XMS memory for swap
  85.   /?         show the command line options
  86.  
  87. When disk space is used for swapping, POPDOS normally uses three swap files.
  88. Two of the files are used to activate the swappable TSR. The first such file
  89. holds the POPDOS code and data and the other one holds the memory contents
  90. that POPDOS overwrites. The third file is used for the DOS shell itself and
  91. consumes about 30K bytes, which is typically much smaller than the first two.
  92. When the /1 option is specified, POPDOS uses a small intermediate buffer which
  93. removes the need for one of the first two files and thus cuts its disk space
  94. requirement by up to a factor of two (see the formula above). However, the
  95. intermediate buffer slows swapping since the swap file is read in smaller (2K
  96. byte vs. 64K byte) blocks and since an extra memory-to-memory move is
  97. required. Nevertheless, the single swap file option is advantageous if it
  98. allows the swap files to fit entirely on a RAM disk. Note that the
  99. intermediate buffer increases the size of the POPDOS resident core by 2K bytes
  100. as well.
  101.  
  102. The /1 option has an analogous effect on the XMS swapping option. When /X /1
  103. is specified, POPDOS uses half as much XMS memory, swaps somewhat slower, and
  104. consumes 2K bytes more normal RAM.
  105.  
  106. When the /A option is specified, POPDOS leaves its swap files visible and
  107. unprotected. Don't delete or overwrite the swap files (which are named
  108. !POPDOS1.SWP, !POPDOS2.SWP, and !POPDOS3.SWP) while POPDOS is loaded. Note
  109. that POPDOS deletes its own swap files when it is unloaded. Although POPDOS
  110. cannot delete the swap files if you turn the machine off while POPDOS is
  111. still loaded, it will correctly overwrite them the next time it's loaded
  112. again.
  113.  
  114. The /D option forces POPDOS to use disk space for swapping even if sufficient
  115. EMS or XMS space is available. You'd specify this option if you have other
  116. applications that will need the EMS or XMS space, or if you have an extended
  117. memory RAM disk that you prefer to use for swapping. Note that POPDOS
  118. allocates space for the TSR-swapping requirement when it goes resident. At the
  119. time it pops up, it allocates another 30K bytes of EMS, XMS, or disk space for
  120. the shell itself.
  121.  
  122. /F lets you specify how many kilobytes of RAM space you'd like to remain free
  123. within your DOS shell. The larger this number, the larger your swap space
  124. requirements will be. The smallest allowed parameter is 30, since DOS itself
  125. won't do much with less than 30KB free. If you don't specify a /F option, the
  126. free space within the shell will be the amount of memory that was free when
  127. POPDOS was loaded, less about 20K.
  128.  
  129. /H allows you to specify a hot key other than the default <Alt><F10>. The
  130. parameter following /H must be in hexadecimal, where the high byte specifies
  131. the shift key combination and the low byte specifies the scan code of the
  132. trigger key. The shift key codes are:
  133.  
  134.   None       - 00
  135.   RightShift - 01
  136.   LeftShift  - 02
  137.   Ctrl       - 04
  138.   Alt        - 08
  139.  
  140. Valid scan codes (in hexadecimal) are:
  141.  
  142.   A - 1E      N - 31      0 - 0B      F1 - 3B      [ - 1A
  143.   B - 30      O - 18      1 - 02      F2 - 3C      ; - 27
  144.   C - 2E      P - 19      2 - 03      F3 - 3D      , - 33
  145.   D - 20      Q - 10      3 - 04      F4 - 3E      / - 35
  146.   E - 12      R - 13      4 - 05      F5 - 3F      \ - 2B
  147.   F - 21      S - 1F      5 - 06      F6 - 40      ] - 1B
  148.   G - 22      T - 14      6 - 07      F7 - 41      ' - 28
  149.   H - 23      U - 16      7 - 08      F8 - 42      . - 34
  150.   I - 17      V - 2F      8 - 09      F9 - 43      ` - 29
  151.   J - 24      W - 11      9 - 0A      F10- 44
  152.   K - 25      X - 2D                  F11- 57
  153.   L - 26      Y - 15                  F12- 58
  154.   M - 32      Z - 2C
  155.  
  156. For example, 0244 means <LeftShift><F10>, 0820 means <Alt><D>, 0517 means
  157. <Ctrl><RightShift><I>.
  158.  
  159. When /K is specified, POPDOS doesn't execute its mouse management code. This
  160. option does nothing unless a mouse is installed. By default, POPDOS saves and
  161. reinitializes the mouse state before it starts the DOS shell and restores the
  162. mouse before returning control to the underlying application. For some mouse
  163. drivers, notably recent versions of Microsoft MOUSE.COM and MOUSE.SYS, the
  164. call to reinitialize the mouse takes an annoyingly long time (a second or so).
  165. /K removes this delay, but if you run a program that enables the mouse within
  166. your DOS shell, you may see a phantom mouse cursor when you return to the
  167. interrupted application.
  168.  
  169. /M disables the swapping message, which POPDOS normally displays whenever it
  170. is swapping to disk or to EMS or XMS when it judges that the swap delay would
  171. be noticeable. /M is particularly useful when you're swapping to a RAM disk.
  172.  
  173. /S specifies an alternate drive and directory for the swap files. The default
  174. location is C:\. All three swap files go to the same place. Note that the
  175. parameter to /S should specify a complete path name, including a drive and
  176. directory but no filename.
  177.  
  178. /X enables the use of XMS memory for swapping. Note that in order to use the
  179. XMS option, you must have an XMS-compatible driver installed. Microsoft
  180. distributes the HIMEM.SYS driver for free (it's available on CompuServe) and
  181. also with some of their products like Windows. Other XMS-compatible drivers
  182. include QEXT.SYS and QEMM.SYS from Quarterdeck and 386MAX.SYS from Qualitas.
  183. The amount of XMS memory required is affected by the /1 option, described
  184. above.
  185.  
  186. Here are some examples of POPDOS command line options:
  187.  
  188. POPDOS /F 200
  189.   Installs POPDOS to support a DOS shell with about 200K bytes free. The
  190.   actual amount will vary slightly depending on the version of DOS. POPDOS
  191.   will need about 256K bytes of EMS space, or 450KB of disk space with dual
  192.   file swap, or 245KB of disk space with single file swap.
  193.  
  194. POPDOS /D /1 /A /M /S G:\
  195.   Forces POPDOS to swap to disk, using single file swapping, leaving the swap
  196.   file visible, turning off the swap message, and locating the swap file in
  197.   the root directory of drive G (which is presumably a RAM disk).
  198.  
  199. POPDOS /X /1 /F 200
  200.   Installs POPDOS to use XMS memory in "single file swap" mode. POPDOS will
  201.   use about 245KB of XMS space and will retain about 9K of normal DOS RAM.
  202.   About 200KB of RAM space will be free when the DOS shell is activated.
  203.  
  204. POPDOS /H 0858
  205.   POPDOS will activate when <Alt><F12> is pressed.
  206.  
  207. POPDOS /U
  208.   Unloads POPDOS.
  209.  
  210. POPDOS /?
  211.   Displays the POPDOS command line options.
  212.  
  213.  
  214. ------- Using POPDOS -------------------------------------------------------
  215.  
  216. Once POPDOS has been installed, just press its hot key. After a short swapping
  217. delay, the screen will clear and the DOS prompt will appear. Execute one or
  218. more DOS commands, then type EXIT to return to the interrupted application.
  219.  
  220. If POPDOS cannot shell to DOS when you request it, it will beep and return to
  221. the current application.
  222.  
  223.  
  224. ------- Restrictions -------------------------------------------------------
  225.  
  226. POPDOS may not be loaded "high" using such utilities as QEMM, QRAM, or
  227. 386MAX. POPDOS requires a large amount of contiguous RAM space that must
  228. immediately follow its kernel in memory.
  229.  
  230. Like any swappable TSR, POPDOS should not be loaded before programs or TSRs
  231. that contain hardware interrupt handlers. Examples include network shells,
  232. asynchronous communications programs, and multitasking operating systems.
  233.  
  234. You may not pop to a DOS shell when you're already at the DOS command line.
  235. (This is not a critical restriction, of course, but it's the first thing that
  236. most people try.) POPDOS protects itself against such a request and just
  237. beeps and returns to the command line. The limitation arises because of the
  238. way DOS manages its internal stacks. For related reasons, you may not shell to
  239. DOS while you're at the DEBUG or EDLIN command line. Similarly, you may not
  240. shell to DOS when you're within another TSR that was popped up at the DOS
  241. command line. The techniques POPDOS uses to detect that it was popped up at
  242. the command line may be fooled by multitasking operating systems such as
  243. DesqView; use POPDOS carefully in these situations.
  244.  
  245. You may not pop to DOS from within a program operating in graphics mode. This
  246. is not a limitation of the swappable TSR itself; POPDOS simply doesn't know
  247. how to save and restore the state of a graphics screen.
  248.  
  249. Do not install another TSR while within a POPDOS shell. The most likely result
  250. will be a system hang when you return from the shell.
  251.  
  252. As mentioned above, POPDOS can't be used with DOS 2.x.
  253.  
  254.  
  255. ------- Providing a DOS Shell in your TSRs -----------------------------------
  256.  
  257. This section assumes that you have the POPDOS source code. The hardest things
  258. that POPDOS does are handled by the OPSWAP and OPEXEC units from Object
  259. Professional. POPDOS itself has been kept simple so that you can see how it
  260. works, extend it, or incorporate the same capabilities in your own programs.
  261.  
  262. The following rules summarize what your program must and must not do. Refer to
  263. POPDOS.PAS (the main program source file) and PDMAIN.PAS (the main unit) for
  264. additional details. In most ways, POPDOS is organized just like any other
  265. swappable TSR, so you should be sure to understand that first.
  266.  
  267. 1. ONLY the main program itself should use the OPEXEC and OPSWAP units. OPSWAP
  268. should be the last unit in the USES statement, and OPEXEC should immediately
  269. precede it.
  270.  
  271. 2. As with other swappable TSRs, the main program consists primarily of just a
  272. call to the installation procedure of the main unit. In this case, the program
  273. must also initialize a few variables in the main unit so that the main unit
  274. can access the routines in OPEXEC. The most essential one is a function
  275. variable, ExecDosSwap, whose declaration mirrors that of the actual
  276. ExecDosSwap function in OPEXEC. In this way, the main unit can call
  277. ExecDosSwap even though it doesn't explicitly use OPEXEC.
  278.  
  279. POPDOS.PAS also stores the address of OPEXEC's UseEmsIfAvailable and
  280. UseXmsIfAvailable flags so that PDMAIN can toggle the flags' values depending
  281. on command line options. POPDOS always turns off the OPEXEC swapping message
  282. since the size of the swap region is never more than about 30K bytes.
  283.  
  284. 3. POPDOS stores two independent flags in the UserData field of the TSR's
  285. external interface record. One of the flags is the typical one: a
  286. success/failure flag that indicates whether the TSR was successfully unloaded
  287. from the DOS command line. The other flag indicates whether the POPDOS shell
  288. is currently active, in which case it's unsafe to unload the TSR. See
  289. procedure TryToUnload for details.
  290.  
  291. 4. Procedure ParseCommandLine shows how to handle all of the common
  292. installation options for a swappable TSR: single swap file, visible swap
  293. files, forced swap to disk, XMS support, etc. It also shows the calculations
  294. required to obtain a specified amount of memory free within the DOS shell
  295. (although these calculations may not be appropriate when the DOS shell is part
  296. of a larger TSR program).
  297.  
  298. 5. Before actually shelling to DOS, the popup routine must check the
  299. DosBusyFlag and WasCommandActive functions of OPSWAP1:
  300.  
  301.    if (DosBusyFlag <> 0) or WasCommandActive then
  302.      {DO NOT shell to DOS} ;
  303.  
  304. The TSR itself will pop up and can perform almost any action under these same
  305. conditions. However, it CANNOT safely shell to DOS if either condition is met.
  306. As previously noted, refusing to shell under these conditions doesn't really
  307. give away much functionality.
  308.  
  309. 6. The popup routine must deal with the video system and the possibility that
  310. the user may switch video modes while in the DOS shell. POPDOS refuses to
  311. shell out if the system is not in a text mode when the request occurs. If the
  312. system is in a text mode, POPDOS saves the contents of the screen, the video
  313. mode, the cursor shape and position, and the mouse state before it clears the
  314. screen and calls ExecDosSwap. On return from the shell, it switches back to
  315. the original video mode if necessary, restores the screen contents, the
  316. cursor, and the mouse state. Note that POPDOS calls WhereXYDirect to get the
  317. initial cursor position; this is necessary to get accurate values when POPDOS
  318. is activated over SideKick, Lotus 1-2-3, or another program that doesn't
  319. position the cursor using BIOS calls.
  320.  
  321. 7. It's deadly for the user to install another TSR while within the POPDOS
  322. shell. POPDOS has no effective way to protect itself against this possibility,
  323. so you must warn your users against it. The typical result of doing so will be
  324. an immediate system crash upon returning from the shell.
  325.  
  326. 8. In order to provide XMS support, you must assure that Object Professional
  327. is correctly configured. Assure that OPDEFINE.INC, OPEXEC.ASM, and OPSWAP.ASM
  328. all enable the SupportXms define and that you've reassembled OPEXEC and OPSWAP
  329. with these defines in place.
  330.  
  331.  
  332. ------- POPDOS License Information -------------------------------------------
  333.  
  334. POPDOS.EXE and its source code, unmodified, may be used freely by individuals
  335. in a home or business environment. You may use POPDOS yourself, give it to
  336. your friends or co-workers, or distribute it for a cost-based fee ($10 or
  337. less) as part of a user's group or bulletin board service. If you wish to
  338. distribute POPDOS as part of a commercial software package, please contact
  339. TurboPower Software for a license agreement.
  340.  
  341. You may incorporate the ideas embodied by POPDOS into programs of your own
  342. design with no additional licenses, subject to the terms of the Object
  343. Professional license agreement.
  344.  
  345. TurboPower Software assumes no liability for the use or abuse of POPDOS.EXE or
  346. the program code it contains.
  347.  
  348. To report problems or suggestions regarding POPDOS, or for more information
  349. about TurboPower's line of programmer's tools, contact Kim Kokkonen at
  350. TurboPower Software:
  351.  
  352.      TurboPower Software
  353.      P.O. Box 66747
  354.      Scotts Valley, CA 95067-0747
  355.  
  356.      408-438-8608 (voice only, Monday-Friday 9AM-5PM)
  357.      CompuServe: 76004,2611
  358.  
  359.  
  360. ------- POPDOS Version History -----------------------------------------------
  361.  
  362. Version 1.02   6/04/90
  363.   Initial release (synchronized with Object Professional 1.02)
  364.  
  365. Version 1.03   7/24/90
  366.   Add support for swapping to XMS
  367.